﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;

namespace HPDI.DrawingStandard
{
    public static class MLPloter
    {
        /// <summary>
        /// 添加空心多线（外轮廓-内轮廓-中线-内轮廓-外轮廓）
        /// </summary>
        /// <param name="St">起点</param>
        /// <param name="Ed">终点</param>
        /// <param name="Width">宽度</param>
        /// <param name="Thickness">厚度</param>
        /// <param name="Ls">轮廓图层</param>
        /// <param name="CutCurveA">起点边界</param>
        /// <param name="CutCurveB">重点边界</param>
        /// <param name="haveCenter">是否生成中心线</param>
        /// <returns></returns>
        public static DBObjectCollection AddTube(Point2d St, Point2d Ed, double Width,double Thickness,string Ls,
            Curve CutCurveA = null, Curve CutCurveB = null,  bool haveCenter = true)
        {
            List<Line> LineSet = new List<Line>();
            DBObjectCollection Res = new DBObjectCollection();
            Line sideA, sideB, ccline, insideA, insideB;

            ccline = new Line(St.C3D(), Ed.C3D());
            sideA = (Line)ccline.GetOffsetCurves(-0.5 * Width)[0];
            sideB = (Line)ccline.GetOffsetCurves(0.5 * Width)[0];

            ccline.Layer = "H中心线";
            sideA.Layer = Ls;
            sideB.Layer = Ls;
            LineSet.Add(sideB);
            LineSet.Add(ccline);
            LineSet.Add(sideA);

            if (Thickness != 0)
            {
                insideA = (Line)ccline.GetOffsetCurves(-0.5 * Width + Thickness)[0];
                insideB = (Line)ccline.GetOffsetCurves(0.5 * Width - Thickness)[0];
                insideA.Layer = "H虚线";
                insideB.Layer = "H虚线";
                LineSet.Add(insideA);
                LineSet.Add(insideB);
            }

            foreach (var item in LineSet)
            {
                Line updateLine;
                if (item.Layer != "H中心线")
                {
                    updateLine = item.UpdateBoundary(CutCurveA, CutCurveB);
                }
                else
                {
                    if (haveCenter)
                    {
                        updateLine = item;
                    }
                    else
                    {
                        continue;
                    }
                }
                Res.Add(updateLine);
            }
            return Res;
        }
    }
}
